<template>
  <div class="page-main" v-title data-title="蚝油清洗消毒方案库">
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>蚝油清洗消毒方案库</span></div>
    <div class="container">
      <div class="container-bg">
        <div class="header">
          <a-row type="flex" justify="space-between" align="middle">
            <a-col>
              <a-button class="hte-btn" type="primary" :loading="genLoading" @click="handleGenerate">生成</a-button>
              <!-- <a-button class="hte-btn" type="primary">保存</a-button> -->
              <a-button class="hte-btn" @click="handAction('upd')">修正</a-button>
              <a-button class="hte-btn" style="margin:0px" :disabled="true">导出:</a-button>
              <a-button class="hte-btn" style="margin:0px" :loading="exportLoading1" @click="handleExportScheme(1,2,'成品方案')">成品方案</a-button>
              <a-button class="hte-btn" style="margin:0px" :loading="exportLoading2"  @click="handleExportScheme(2,2,'成品顶料')">成品顶料</a-button>
              <a-button class="hte-btn" style="margin:0px" :loading="exportLoading3"  @click="handleExportScheme(1,3,'淀粉方案')">淀粉方案</a-button>
              <a-button class="hte-btn" style="margin:0px" :loading="exportLoading4"  @click="handleExportScheme(1,4,'蚝油混合液方案')">蚝油混合液方案</a-button>
              <a-button class="hte-btn"  @click="handlePostExportXls('蚝油清洗消毒方案库')">当前列表</a-button>
              <a-button class="hte-btn" type="danger" @click="handAction('del')">删除</a-button>
              <a-button class="hte-btn" @click="refresh">刷新</a-button>
            </a-col>
            <a-col>
              <a-radio-group v-model="radioType" button-style="solid" @change="handRadio">
                <a-radio-button value="/clearSoln/burden/list">配料主数据</a-radio-button>
                <a-radio-button value="/clearSoln/finished/list">品种主数据</a-radio-button>
                <a-radio-button value="/clearSoln/clear/list">方案主数据</a-radio-button>
              </a-radio-group>
            </a-col>
            <a-col class="input-ground">
              <a-input-group compact>
                <a-select v-model="searchField" @change="changeKeywordType">
                  <a-select-option value="schemeNoStr"> 清消方案编号 </a-select-option>
                  <a-select-option value="upProdNo"> 上品种编号 </a-select-option>
                  <a-select-option value="upProdName"> 上品种名称 </a-select-option>
                  <a-select-option value="downProdNo"> 下品种编号 </a-select-option>
                  <a-select-option value="downProdName"> 下品种名称 </a-select-option>
                </a-select>
                <a-input-search
                  v-model="searchValue"
                  @search="doSearch"
                  @change="changeSearchValue"
                  allowClear
                  placeholder="请输入关键词检索"
                />
              </a-input-group>
              <a-button class="hte-btn del-btn" @click="visibleModel = true">高级查询</a-button>
            </a-col>
          </a-row>
        </div>
        <div class="content">
          <a-table
            class="hte-table-content"
            :scroll="{ x: 1600 }"
            :columns="columns"
            :data-source="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            rowKey="id"
            size="middle"
            @change="handleTableChange"
          >
            <template slot="difference" slot-scope="text, record">
              <template v-if="!record.upDiff && !record.downDiff">
                <div>无</div>
              </template>
              <template v-else>
                <div>上：
                  <span v-html="record.upDiff"></span>
                  <!-- <span class="warn">xxxx</span> -->
                </div>
                <div>下：
                  <span v-html="record.downDiff"></span>
                </div>
              </template>
            </template>
            <template slot="upProd" slot-scope="text, record">
              <span class="clickspan" @click="handAction('det', record.upProd)">{{ text }}</span>
            </template>
            <template slot="downProd" slot-scope="text, record">
              <span class="clickspan" @click="handAction('det', record.downProd)">{{ text }}</span>
            </template>
          </a-table>
        </div>
      </div>
    </div>
    <a-back-top class="backtodom" />
    <!-- 高级查询 -->
    <advanced-search
      :dataForm.sync="queryParam"
      :visible="visibleModel"
      ref="advanced"
      :formCol="queryParamCol"
      @ok="callBackResult"
      @reset="resetResulte"
      @close="closeResulte"
    >
    </advanced-search>

    <!-- 修改 -->
    <DisinfectModal ref="editModal" @ok="doSearch"></DisinfectModal>
  </div>
</template>
<script>
import Vue from 'vue'
import { getAction, postAction,downloadFileLink } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import { USER_INFO } from '@/store/mutation-types'
import { ClearLibMixin } from '@/mixins/ClearLibMixin'
export default {
  name: 'BurdenList',
  mixins: [ClearLibMixin,JeecgListMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    AdvancedSearch: () => import('@/components/tools/AdvancedSearch'),
    DisinfectModal: () => import('./disinfectModal'),
  },
  data() {
    return {
        disableMixinCreated:true,
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'ClearList',
      },
      radioType: '',
      currUser: Vue.ls.get(USER_INFO).username,
      columns: [
        {
          title: '清消方案编号',
          dataIndex: 'schemeNoStr',
          width: 120,
          align: 'center',
        },
        { title: '上品种编号', dataIndex: 'upProdNo', width: 120, align: 'center',scopedSlots: { customRender: 'upProd' } },
        { title: '上品种名称', dataIndex: 'upProdName', width: 120, align: 'center', ellipsis: true },
        { title: '下品种编号', dataIndex: 'downProdNo', width: 120, align: 'center', scopedSlots: { customRender: 'downProd' } },
        { title: '下品种名称', dataIndex: 'downProdName', width: 120, align: 'center',ellipsis: true },
        { title: '配料差异', dataIndex: '', width: 180, align: 'left', scopedSlots: { customRender: 'difference' }},
        { title: '过敏原特性', dataIndex: 'matFeatureName', width: 140, align: 'center',ellipsis: true},
        { title: '特殊气味特性', dataIndex: 'smell', width: 140, align: 'center',
          customRender: (text) => {
            if (text == 1) {
              return '含特殊气味';
            } else {
              return '无特殊气味';
            }
          }
        },
        { title: '清洗方案', dataIndex: 'washWayCode', width: 120, align: 'center',ellipsis: true },
        { title: '系统', dataIndex: 'systemName', width: 80, align: 'center'},
        { title: '清洗时长(h)', dataIndex: 'washDuration', width: 100, align: 'center'},
        { title: '顶料量(kg)', dataIndex: 'subWeight', width: 100, align: 'center'},
        { title: '顶料时长(h)', dataIndex: 'subDuration', width: 100, align: 'center'},
        { title: '转规时长(h)', dataIndex: 'specDuration', width: 100, align: 'center'},
        { title: '转标时长(h)', dataIndex: 'labelDuration', width: 110, align: 'center'},
      ],
      url: {
        generate:'/hteWashScheme/generate',
        list: '/hteWashScheme/page', // 搜索
        delBatch: '/hteWashScheme/delBatch', // 删除
        exportScheme: '/hteWashScheme/exportScheme', // 导出
        exportXlsUrl:'/hteWashScheme/exportList'
      },
      // 高级查询
      visibleModel: false,
      searchField: 'schemeNoStr',
      searchValue: '',
      queryParam: {
        orderNo: '',
        uporderNo: '',
      },
      queryParamCol: [
        { type: 'input', model: 'schemeNoStr', label: '清消方案编号' },
        { type: 'input', model: 'upProdNo', label: '上品种编号' },
        { type: 'input', model: 'upProdName', label: '上品种名称' },
        { type: 'input', model: 'downProdNo', label: '下品种编号' },
        { type: 'input', model: 'downProdName', label: '下品种名称' },
        { type: 'select', model: 'system', label: '系统',dictList:[{code:1,name:'系统1'},{code:2,name:'系统2'},{code:3,name:'系统3'},{code:4,name:'系统4'},
          {code:5,name:'系统5'},{code:6,name:'系统6'},{code:7,name:'系统7'},{code:8,name:'系统8'},{code:9,name:'系统9'},{code:10,name:'系统10'},{code:11,name:'系统11'}]},

      ],
       ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '50', '100'],
          showTotal: (total, range) => {
              return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
      },
      exportLoading1:false,
      exportLoading2:false,
      exportLoading3:false,
      exportLoading4:false,
      genLoading:false
    }
  },
   created(){
     this.loadData(1);

  },
  mounted() {
  },
  methods: {

    refresh() {
      this.loadData()
    },
    doSearch() {
      this.loadData(1)
    },
    changeKeywordType() {
      this.queryParam={};
      this.$set(this.queryParam, this.searchField, this.searchValue)
    },
    changeSearchValue(){
      this.$set(this.queryParam, this.searchField, this.searchValue)
    },
    handRadio(){
      let routeUrl = this.$router.resolve({
        path: this.radioType
      });
      window.open(routeUrl.href, '_blank');
    },
    /**
     * 高级搜索
     */
    callBackResult() {
      this.visibleModel = false
      this.doSearch()
    },
    closeResulte() {
      this.visibleModel = false
    },
    resetResulte() {
      this.queryParam = {}
    },

    handleGenerate(){
      const that = this;
      this.genLoading = true;
      getAction(that.url.generate,{washType:this.washType}).then((res) => {
        if (res.code == 200) {
          that.$message.success('生成成功')
          that.loadData();
        } else {
          that.$message.error(res.message)
        }
        that.genLoading = false;
      })
    },
    /**
     * 操作
     */
    handAction(type, item) {
      switch (type) {
        case 'del':
          // 删除，可多选
          const that = this
          if (this.selectedRowKeys.length == 0) {
            this.$message.warning('请选择至少一条数据！')
            return
          }
          this.$confirm({
            title: '确认删除',
            content: '请确认是否删除此信息?',
            onOk: function () {
              postAction(that.url.delBatch, that.selectedRowKeys).then((res) => {
                if (res.code == 200) {
                  that.$message.success('删除成功')
                  that.loadData();
                } else {
                  that.$message.warning('删除失败:' + res.message)
                }
              })
            },
          })
          break
        case 'det':
          let routeUrl = this.$router.resolve({
            path: `/clearSoln/finished/info?id=${item}`
          });
          window.open(routeUrl.href, '_blank');
          break
        case 'upd':
          // 修改
          if (this.selectedRowKeys.length != 1) {
            this.$message.warning('请选择一条数据！')
            return
          }
          this.$refs.editModal.showVisible(this.selectionRows[0].id)
          break
        default:
          break
      }
    },
    handleExportScheme(type,prodType,fileName){
      if(type==1 && prodType==2){
        this.exportLoading1 = true;
      }else if(type==2 && prodType==2){
        this.exportLoading2 = true;
      }else if(prodType==3){
        this.exportLoading3 = true;
      }else if(prodType==4){
        this.exportLoading4 = true;
      }
      const param={type:type,prodType:prodType,washType:this.washType}
      downloadFileLink(this.url.exportScheme,fileName + '.xlsx', param,{type: 'application/vnd.ms-excel'}).then((data)=>{
        this.exportLoading1 = false;
        this.exportLoading2 = false;
        this.exportLoading3 = false;
        this.exportLoading4 = false;
      })
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
@import '~@views/library/clearSoln/index.less';
.warn{color: #ff4d4f;}
</style>
